<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			var random = parseInt(Math.random() * 100 + 1);
			function compare() {
				var num = document.getElementById("numId").value;
				var result = document.getElementById("resultId");
				var reg = /[0-9]+/g;
				if(num != num.match(reg)){
					result.innerHTML = "<span style='color:red;'>请输入一个数字</span>";
					return;
				}
				if (num > random) {
					result.innerHTML = "<span>大了</span>";
				} else if (num < random) {
					result.innerHTML = "<span>小了</span>";
				} else {
					result.innerHTML = "<span>猜对了</span>";
				}
			}
		</script>
	</head>
	<body>
		<input type="text" id="numId" />
		<input type="button" value="猜" onclick="compare()" />
		<span id="resultId"></span>
	</body>
</html>
